package com.jdkreader.concurrency.concurrent.delay;

import java.util.Random;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DelayQueueDemo {

    public static void main(String[] args) {
        Random random = new Random(47);
        ExecutorService exec= Executors.newCachedThreadPool();
        DelayQueue<DelayedTask> queue=new DelayQueue<DelayedTask>();
        for(int i=0;i<20;i++){
            queue.put(new DelayedTask(new Random().nextInt(5000)));
        }
        queue.add(new EndSentinel(5000,exec));
        exec.execute(new DelayedTaskConsumer(queue));
    }
}
